﻿#region Header
// Copyright 2007-2011, Jerónimo Milea
// 
// This file is part of NetJsWire.
// 
//     NetJsWire is free software: you can redistribute it and/or modify
//     it under the terms of the GNU General Public License as published by
//     the Free Software Foundation, either version 3 of the License, or
//     (at your option) any later version.
// 
//     NetJsWire is distributed in the hope that it will be useful,
//     but WITHOUT ANY WARRANTY; without even the implied warranty of
//     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//     GNU General Public License for more details.
// 
//     You should have received a copy of the GNU General Public License
//     along with NetJsWire.  If not, see <http://www.gnu.org/licenses/>.
#endregion

using System.ComponentModel;
using NetJsWire.JsonRpcHandler;
using NetJsWire.Widgets.Core;

namespace NetJsWire.Widgets.Config
{
    public class DataViewConfigOptions : BoxComponentConfigOptions
    {
        private bool _blockRefresh;

        private bool _deferEmptyText;

        private string _emptyText;

        private string _itemSelector;

        private string _loadingText;

        private bool _multiSelect;

        private string _overClass;

        private string _selectedClass = "x-view-selected";

        private bool _simpleSelect;

        private bool _singleSelect;

        private IDataStore _store;

        private bool _trackOver;

        public DataViewConfigOptions( IWidget ownerWidget )
            : base( ownerWidget )
        {
        }

        /// <summary>
        ///   Set this to true to ignore datachanged events on the bound store.
        ///   This is useful if you wish to provide custom transition animations via a plugin (defaults to false)
        /// </summary>
        [Description( "Set this to true to ignore datachanged events on the bound store." ), DefaultValue( false ), Browsable( true )]
        public override bool BlockRefresh
        {
            get { return _blockRefresh; }
            set
            {
                SetValue( "blockRefresh", value, false, _blockRefresh );
                _blockRefresh = value;
            }
        }

        /// <summary>
        ///   True to defer emptyText being applied until the store's first load.
        /// </summary>
        [Description( "True to defer emptyText being applied until the store's first load." ), DefaultValue( false ), Browsable( true )]
        public override bool DeferEmptyText
        {
            get { return _deferEmptyText; }
            set
            {
                SetValue( "deferEmptyText", value, false, _deferEmptyText );
                _deferEmptyText = value;
            }
        }

        /// <summary>
        ///   The text to display in the view when there is no data to display (defaults to '').
        /// </summary>
        [Browsable( true )]
        [Description( "The text to display in the view when there is no data to display (defaults to '')." ), DefaultValue( ( string ) null )]
        public override string EmptyText
        {
            get { return _emptyText; }
            set
            {
                SetValue( "emptyText", value, null, _emptyText );
                _emptyText = value;
            }
        }

        /// <summary>
        ///   This is a required setting. A simple CSS selector (e.g. div.some-class or span:first-child) that will be used to determine what nodes this DataView will be working with.
        /// </summary>
        [Browsable( true )]
        [Description( "This is a required setting. A simple CSS selector (e.g. div.some-class or span:first-child) that will be used to determine what nodes this DataView will be working with." ), DefaultValue( ( string ) null )]
        public override string ItemSelector
        {
            get { return _itemSelector; }
            set
            {
                SetValue( "itemSelector", value, null, _itemSelector );
                _itemSelector = value;
            }
        }

        /// <summary>
        ///   A string to display during data load operations (defaults to undefined).
        ///   If specified, this text will be displayed in a loading div and the view's contents will be cleared while loading, otherwise the view's contents will continue to display normally until the new data is loaded and the contents are replaced.
        /// </summary>
        [Browsable( true )]
        [Description( "A string to display during data load operations (defaults to undefined)." ), DefaultValue( ( string ) null )]
        public override string LoadingText
        {
            get { return _loadingText; }
            set
            {
                SetValue( "loadingText", value, null, _loadingText );
                _loadingText = value;
            }
        }

        /// <summary>
        ///   True to allow selection of more than one item at a time, false to allow selection of only a single item at a time or no selection at all, depending on the value of singleSelect (defaults to false).
        /// </summary>
        [Browsable( true )]
        [Description( "True to allow selection of more than one item at a time, false to allow selection of only a single item at a time or no selection at all, depending on the value of singleSelect (defaults to false)." ), DefaultValue( false )]
        public override bool MultiSelect
        {
            get { return _multiSelect; }
            set
            {
                SetValue( "multiSelect", value, false, _multiSelect );
                _multiSelect = value;
            }
        }

        /// <summary>
        ///   A CSS class to apply to each item in the view on mouseover (defaults to undefined).
        /// </summary>
        [Browsable( true )]
        [Description( "A CSS class to apply to each item in the view on mouseover (defaults to undefined)." ), DefaultValue( ( string ) null )]
        public override string OverClass
        {
            get { return _overClass; }
            set
            {
                SetValue( "overClass", value, null, _overClass );
                _overClass = value;
            }
        }

        /// <summary>
        ///   A CSS class to apply to each selected item in the view (defaults to 'x-view-selected').
        /// </summary>
        [Browsable( true )]
        [Description( "A CSS class to apply to each selected item in the view (defaults to 'x-view-selected')." ), DefaultValue( "x-view-selected" )]
        public override string SelectedClass
        {
            get { return _selectedClass; }
            set
            {
                SetValue( "selectedClass", value, "x-view-selected", _selectedClass );
                _selectedClass = value;
            }
        }

        /// <summary>
        ///   True to enable multiselection by clicking on multiple items without requiring the user to hold Shift or Ctrl, false to force the user to hold Ctrl or Shift to select more than on item (defaults to false).
        /// </summary>
        [Browsable( true )]
        [Description( "True to enable multiselection by clicking on multiple items without requiring the user to hold Shift or Ctrl, false to force the user to hold Ctrl or Shift to select more than on item (defaults to false)." ), DefaultValue( false )]
        public override bool SimpleSelect
        {
            get { return _simpleSelect; }
            set
            {
                SetValue( "simpleSelect", value, false, _simpleSelect );
                _simpleSelect = value;
            }
        }

        /// <summary>
        ///   True to allow selection of exactly one item at a time, false to allow no selection at all (defaults to false).
        /// </summary>
        /// <remarks>
        ///   Note that if multiSelect = true, this value will be ignored.
        /// </remarks>
        [Browsable( true )]
        [Description( "True to allow selection of exactly one item at a time, false to allow no selection at all (defaults to false)." ), DefaultValue( false )]
        public override bool SingleSelect
        {
            get { return _singleSelect; }
            set
            {
                SetValue( "singleSelect", value, false, _singleSelect );
                _singleSelect = value;
            }
        }

        /// <summary>
        ///   The Ext.data.Store to bind this DataView to.
        /// </summary>
        [Browsable( true )]
        [AttributeProvider( typeof( IDataStore ) )]
        [Description( "The Ext.data.Store to bind this DataView to." ), DefaultValue( null )]
        public override IDataStore Store
        {
            get { return _store; }
            set
            {
                if ( value != null )
                    SetValue( "store", string.Format( "Ext.StoreMgr.get('{0}')", value.Renderer.InternalID ), null, _store );
                else
                    SetValue( "store", value, null, _store );

                _store = value;
            }
        }

        /// <summary>
        ///   True to enable mouseenter and mouseleave events.
        /// </summary>
        [Browsable( true )]
        [Description( "True to enable mouseenter and mouseleave events." ), DefaultValue( false )]
        public override bool TrackOver
        {
            get { return _trackOver; }
            set
            {
                SetValue( "trackOver", value, false, _trackOver );
                _trackOver = value;
            }
        }

        #region Overrides

        /// <summary>
        ///   The registered xtype to create.
        ///   This config option is not used when passing a config object into a constructor.
        ///   This config option is used only when lazy instantiation is being used, and a child item of a Container is being specified not as a fully instantiated Component, but as a Component config object.
        ///   The xtype will be looked up at render time up to determine what type of child Component to create.
        /// </summary>
        [Description( "The registered xtype to create. This config option is not used when passing a config object into a constructor." )]
        [Browsable( true )]
        [DefaultValue( "dataview" )]
        [TypeConverter( typeof( XtypeStringConverter ) )]
        public override string Xtype
        {
            get
            {
                return base.Xtype;
            }
            set
            {
                base.Xtype = value;
            }
        }

        #endregion
    }
}